package com.example.tool.task;



import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public class demo {
//    public static void main(String[] args) {
//        Map<String, Object> map = new HashMap<String, Object>();
//        map.put("a", "a");
//        map.put("b", "123");
//
//        String hpvJsonString = JSON.toJSONString(map);
//        System.out.println(hpvJsonString);
//        /**
//         *
//
//         */
//    }
//public static void main(String[] args) {
//
//    String s="MSH111111MSH22222";
//    String SS="MSH1";
//    String[] mshes = s.split("MSH");
//    for (String data:mshes
//         ) {
//        System.out.println(data);
//    }
//
//}

public static void main(String[] args) {
        String data="Q|1|^^        X3920000192001^0^5081^1^^S1^SC||ALL||||||||O";

    String codeType = getIndexString(data, 2, 3, "|");
    log.info((new StringBuilder("codeType:")).append(codeType).toString());
    String strSubBarcode = getIndexString(codeType, 2, 3, "^");
    log.info((new StringBuilder("strSubBarcode:")).append(strSubBarcode).toString());
    String rackNo = codeType.substring(getStringIndex(codeType, "^", 3) + 1);
    log.info((new StringBuilder("rackNo:")).append(rackNo).toString());
//    codeType:^^        X3920000192001^0^5081^1^^S1^SC
//    strSubBarcode:        X3920000192001
//    rackNo:0^5081^1^^S1^SC

//文件改名，避免重复上传
//    if (isSuccess) {
//        file.renameTo(new File(file.getPath() + "success"));
//    }else {
//        file.renameTo(new File(file.getPath() + "fail"));
//    }



}

    public static int getStringIndex(String inString, String Char, int charNumber)
    {
        int j = 0;
        for(int i = 0; i <= inString.length() - 1; i++) {
            if(i + Char.length() <= inString.length() && inString.substring(i, i + Char.length()).equals(Char) && ++j == charNumber) {
                return i;
            }
        }
        return 0;
    }
    public static String getIndexString(String strOragail, int intStart, int intEnd, String Split)
    {
        int start = getStringIndex(strOragail, Split, intStart);
        int end = getStringIndex(strOragail, Split, intEnd);
        if(start + 1 <= end)
        {
            return strOragail.substring(start + 1, end);
        } else
        {
            System.out.println("Not Find  Is Start Index > End.......");
            return "";
        }
    }
    public static String subByteString(String str, int toCount, String more)
    {
        int reInt = 0;
        String reStr = "";
        if(str == null) {
            return "";
        }
        char tempChar[] = str.toCharArray();
        for(int kk = 0; kk < tempChar.length && toCount > reInt; kk++)
        {
            String s1 = String.valueOf(tempChar[kk]);
            byte b[] = s1.getBytes();
            reInt += b.length;
            reStr = (new StringBuilder(String.valueOf(reStr))).append(tempChar[kk]).toString();
        }
        if(toCount == reInt || toCount == reInt - 1) {
            reStr = (new StringBuilder(String.valueOf(reStr))).append(more).toString();
        }
        return reStr;
    }

}
